package so.sao.code.service.domain.entity;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;

import lombok.Data;
import so.sao.code.dto.enums.ThirdPartyCodeFileStatus;
import so.sao.code.service.domain.CodeType;
import so.sao.code.service.domain.FileType;
import so.sao.code.service.infrastructure.jpa.convert.CodeTypeConvert;
import so.sao.code.service.infrastructure.jpa.convert.FileTypeConvert;
import so.sao.code.service.infrastructure.jpa.convert.ThirdPartyCodeFileStatusConvert;

/**
 * 第三方法码对应的url文件云存储的相关处理参数
 *
 * eseId, fileName 为唯一索引。
 */
@Entity
@Data
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "companyId", "fileName" }) })
public class ThirdPartyCodeFileRecord extends BaseEntity {

	/**
	 *
	 */
	private static final long serialVersionUID = -638255868423907021L;

	/**
	 * 供应商ID
	 */
	@Column(nullable = false)
	private Long eseId;

	/**
	 * 客户企业ID
	 */
	@Column(nullable = false)
	private Long companyId;

	/**
	 * 上传用户Id，占位。
	 */
	@Column(nullable = false)
	private Long csId = 0L;

	/**
	 * 容器名称
	 */
	@Column(nullable = false)
	private String containerName;

	/**
	 * 文件路径
	 */
	@Column(nullable = false)
	private String filePath;

	/**
	 * 文件名
	 */
	@Column(nullable = false)
	private String fileName;

	/**
	 * 文件类型，zip/txt/csv
	 */
	@Column(nullable = false)
	@Convert(converter = FileTypeConvert.class)
	private FileType fileType;

	/**
	 * 码类型
	 */
	@Column(nullable = false)
	@Convert(converter = CodeTypeConvert.class)
	private CodeType codeType;

	/**
	 * 密码
	 */
	@Column(nullable = true)
	private String parsePassWord;

	/**
	 * 开始序号
	 */
	@Column(nullable = true)
	private Long seqNumStart;

	/**
	 * 结束序号
	 */
	@Column(nullable = true)
	private Long seqNumEnd;

	/**
	 * tagBatchId
	 */
	@Column(nullable = true)
	private Long tagBatchId;

	/**
	 * 是否开启scheduler。 null,0:不开启；1:开启；10：正在执行中。
	 */
	@Column(nullable = true)
	private Integer scheduler = 0;

	/**
	 * 是否有异常发生 null,0:无异常；1:异常发生
	 */
	@Column(nullable = true)
	private Integer exception = 0;

	/**
	 * remark
	 */
	@Column(nullable = true)
	private String remark;

	/**
	 * status
	 */
	@Column(nullable = false)
	@Convert(converter = ThirdPartyCodeFileStatusConvert.class)
	private ThirdPartyCodeFileStatus status = ThirdPartyCodeFileStatus.NOTHING;

	/**
	 * version
	 */
	@Column(nullable = true)
	@Version
	private Integer version;

	/**
	 * 二维码域名
	 * <p>
	 * 与子域名联合决定二维码数据被存放到哪个库里
	 */
	@Column(nullable = true)
	private String domain;

	/**
	 * 二维码子域名
	 * <p>
	 * 用于决定用哪个密码生成二维码加密串
	 */
	@Column(nullable = true)
	private String subDomain;

	/**
	 * 瓶数
	 */
	@Column(nullable = true)
	private Integer capCount;

	/**
	 * 箱数
	 */
	@Column(nullable = true)
	private Integer packageCount;

	/**
	 * 产品批次。
	 */
	@Column(nullable = true)
	private String productBatch;

	/**
	 * terminal。
	 */
	@Column(nullable = true)
	private String terminal;
	
	/**
	 * messageId。
	 */
	@Column(nullable = true)
	private String messageId;
	
	public enum CodeScheduler {
		CLOSED(0, "关闭"), OPENED(1, "开启"), DOING(10, "执行中");

		private Integer value;

		private String name;

		CodeScheduler(Integer value, String name) {
			this.value = value;
			this.name = name;
		}

		public Integer getValue() {
			return value;
		}

		public void setValue(Integer value) {
			this.value = value;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

	}

	public enum CodeException {
		NO_EXCEPTION(0, "正常"), EXCEPTION(1, "异常");

		private Integer value;

		private String name;

		CodeException(Integer value, String name) {
			this.value = value;
			this.name = name;
		}

		public Integer getValue() {
			return value;
		}

		public void setValue(Integer value) {
			this.value = value;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

	}

}
